﻿<!--#include file="h.asp"--><%
'
'	七色虎建站系统
'	会员信息页面
'	2011.11.2

Sub main
	Dim a,rs,sql,userid,id,body_,userid_,link_
	Dim pagesize,i,page,pagecount,flag
	checkLogin()'验证登录
	a=getN("a", 0)
	userid=user_array(0)
	hu.title = "消息记录"
	body_ = "[div=nav]-"&hu.url("?aid=index","首页")&"-"&hu.url("bbs_user.asp","会员中心")&"-消息记录[/div]"
	Select Case a
		Case 0:'未看过的消息
			sql = "select top 10 m.id,m.content,m.savetime,m.userid,u.name from 74hu_message m left join 74hu_user u on m.userid=u.id where m.state=0 and m.receive="&userid&" and m.flag<>"&userid&" order by m.id desc"
			Set rs=hu.conn(sql)
			If Not rs.eof Then
				' count=rs.recordcount
				' body_ = body_ & "共"&count&"条未看消息<br/>"
				' pagesize=10
				' page=getN("page",1)
				' if page<=0 then page=1
				' pagecount=(count+pagesize-1)\pagesize
				' if page>pagecount then page=pagecount
				' rs.move(pagesize*(page-1))
				' For i=1 To count
				i=1
				While Not rs.eof
					' If rs.eof Then Exit For
					userid_ =rs("userid")
					If userid_<>0 Then
						link_=hu.url("bbs_user.asp?id="&userid_, nowml(rs("name")) )
					Else
						link_=showImg("system")&"系统信息"
					End If
					tid = rs("id")
					body_ = body_ & "[div=odd]"&i&"."&link_&" "& forDate2(rs("savetime")) & "<br/>"&_
						hu.url("bbs_msgs.asp?id="&tid&"&amp;a=2", getLeft(rs("content"),10))&"[/div]"&_
						"[div=even]"&showImg("del")&hu.url("bbs_msgs.asp?id="&tid&"&amp;a=3","删除这条记录")&"[/div]"
					rs.movenext
					i=i+1
				Wend
				' Next
				' body_ = body_ & showPage("bbs_msgs.asp", "a:"&a, page, pagecount)
			Else
				body_ = body_ & "没有新消息!<br/>"
			End If
			rs.close
			Set rs=Nothing
			body_ = body_ & "[div=nav]※功能面板[/div]"&""&showImg("msgto")&hu.url("bbs_msgs.asp?id="&id&"&amp;a=1","全部记录")&_
				""&showImg("del")&hu.url("bbs_msgs.asp?a=3","删除全部消息")&"<br/>[div=nav]※温馨提示[/div]"&_
				"1.当前显示最新的10条信息<br/>2.网站为您保存"&bbsMsgKeep&"天的记录<br/>3.请勿轻信汇款、中奖信息"
		Case 1:'看过的消息
			sql = "select m.id,m.content,m.savetime,m.userid,u.name from 74hu_message m left join 74hu_user u on m.userid=u.id where (m.receive="&userid&" or m.userid="&userid&") and m.flag<>"&userid&" order by m.id desc"
			Set rs = Server.CreateObject("ADODB.Recordset")
			rs.open sql, hu.db, 1, 1
			If Not rs.eof Then
				count = rs.recordcount
				body_ = body_ & "共"&count&"条消息<br/>"
				pagesize=10
				page=getN("page",1)
				if page<=0 then page=1
				pagecount=(count+pagesize-1)\pagesize
				if page>pagecount then page=pagecount
				rs.move(pagesize*(page-1))
				For i=1 To PageSize
					If rs.eof Then Exit For
					userid_ =rs("userid")
					If userid_<>0 Then
						link_=hu.url("bbs_user.asp?id="&userid_, nowml(rs("name")) )
					Else
						link_=showImg("system")&"系统信息"
					End If
					tid = rs("id")
					body_ = body_ & "[div=odd]"&pagesize*(page-1)+i&"."&link_&" "& forDate2(rs("savetime")) & "<br/>"&_
						hu.url("bbs_msgs.asp?id="&tid&"&amp;a=2", getLeft(rs("content"),10))&"[/div]"&_
						"[div=even]"&showImg("del")&hu.url("bbs_msgs.asp?id="&tid&"&amp;a=3","删除这条记录")&"[/div]"
					rs.movenext
				Next
				body_ = body_ & showPage("bbs_msgs.asp", "a:"&a, page, pagecount)
			Else
				body_ = body_ & "暂时没有消息!"
			End If
		Case 2:'查看详细
			id=getN("id",0)
			sql = "select top 1 m.userid,m.content,m.savetime,m.state,u.name from 74hu_message m left join 74hu_user u on m.userid=u.id where m.id="&id&_
				" and (m.receive="&userid&" or m.userid="&userid&") and m.flag<>"&userid&" "
			Set rs=hu.conn(sql)
			If Not rs.eof Then
				userid_=rs("userid")
				If userid_<>0 Then
					link_=hu.url("bbs_user.asp?id="&userid_, nowml(rs("name")) )
				Else
					link_=showImg("system")&"系统信息"
				End If
				body_ = body_ & "[div=odd]"&link_&" "& forDate2(rs("savetime")) & "[/div]"&_
					"[div=even]"&noubb(rs("content"))&"[/div]"
				If rs("userid")<>userid And rs("state")=0 Then
					hu.conn("update 74hu_message set state=1 where id="&id)
				End If
				If userid_<>0 Then body_ = body_ & "[div=odd]"&showImg("msgto")&hu.url("bbs_msg.asp?id="&userid_, "回复信息")&"[/div]"
			Else
				body_ = body_ & "没有这条消息!"
			End If
			rs.close
			Set rs=Nothing
		Case 3:'删除记录
			id=getN("id",0)
			'id=0 表示删除全部信息,其他表示只删除该 id 的信息
			If id>0 Then
				sql ="select flag,userid from 74hu_message where id="&id&" and (receive="&userid&" or userid="&userid&")"
				Set rs=hu.conn(sql)
				If Not rs.eof Then
					userid_=rs("userid")
					flag=rs("flag")
					If userid_<>0 Then
						If flag=0 Then'消息双方公用,因此删除要确认两次
							hu.conn("update 74hu_message set flag="&userid&" where id="&id&"")
							body_ = body_ & "消息删除成功!"
						ElseIf flag=userid Then
							body_ = body_ & "没有这条消息!"
						Else
							hu.conn("delete from 74hu_message where id="&id&"")
							body_ = body_ & "消息删除成功!"
						End If
					Else'userid_ = 0 表示系统信息,可直接删除
						hu.conn("delete from 74hu_message where id="&id&"")
						body_ = body_ & "消息删除成功!"
					End If
				Else
					body_ = body_ & "没有这条消息!"
				End If
			Else
				'表示删除全部信息
				'消息双方公用,因此删除要确认两次
				hu.conn("delete from 74hu_message where receive="&userid&" or userid=0")'直接删除系统信息
				hu.conn("delete from 74hu_message where flag<>"&userid&" and flag<>0 and (receive="&userid&" or userid="&userid&")")
				hu.conn("update 74hu_message set flag="&userid&" where flag=0 and (receive="&userid&" or userid="&userid&")")
				body_ = body_ & "全部消息删除成功!"
			End If
	End Select
	hu.body = comUbb(body_) & ""
End Sub

%>